WT_DECLARE_WT_MEMBER(1,JavaScriptConstructor,"WGLWidget",function(E,h){function F(){var a=jQuery.data(h,"obj"),d="";for(var l in a.jsValues)if(a.jsValues.hasOwnProperty(l)){d+=l+":";for(var o=0;o<a.jsValues[l].length;o++){d+=a.jsValues[l][o];d+=o!==a.jsValues[l].length-1?",":";"}}return d}jQuery.data(h,"obj",this);var w=this,g=E.WT,q=g.glMatrix.vec3,j=g.glMatrix.mat4;this.ctx=null;this.initializeGL=function(){};this.paintGL=function(){};this.resizeGL=function(){};this.updates=[];this.initialized=
false;this.preloadingBuffers=this.preloadingTextures=0;this.jsValues={};this.discoverContext=function(a,d){if(h.getContext){try{this.ctx=h.getContext("webgl",{antialias:d})}catch(l){}if(this.ctx===null)try{this.ctx=h.getContext("experimental-webgl",{antialias:d})}catch(o){}if(this.ctx===null){h.parentNode.insertBefore(h.firstChild,h);h.style.display="none";a()}}return this.ctx};if(h.addEventListener){h.addEventListener("webglcontextlost",function(a){a.preventDefault();w.initialized=false},false);
h.addEventListener("webglcontextrestored",function(){Wt.emit(h,"contextRestored")},false)}var e=null;this.setMouseHandler=function(a){e=a;e.setTarget&&e.setTarget(this)};this.LookAtMouseHandler=function(a,d,l,o,x){function y(b){b=Math.pow(1.2,b);j.translate(f,i);j.scale(f,[b,b,b]);q.negate(i);j.translate(f,i);q.negate(i);w.paintGL()}function z(b){var c=f[5]/q.length([f[1],f[5],f[9]]),m=f[6]/q.length([f[2],f[6],f[10]]);c=Math.atan2(m,c);m=b.x-p.x;var v=b.y-p.y,A=q.create();A[0]=f[0];A[1]=f[4];A[2]=
f[8];var r=j.create();j.identity(r);j.translate(r,i);v=v*s;if(Math.abs(c+v)>=Math.PI/2)v=(c>0?1:-1)*Math.PI/2-c;j.rotate(r,v,A);j.rotate(r,m*G,k);q.negate(i);j.translate(r,i);q.negate(i);j.multiply(f,r,f);w.paintGL();p=b}var f=a,i=d,k=l,s=o,G=x,C=null,t=null,u=null,p=null,D=this;this.mouseDown=function(b,c){g.capture(null);g.capture(h);p=g.pageCoordinates(c)};this.mouseUp=function(){if(p!==null)p=null};this.mouseDrag=function(b,c){if(p!==null){b=g.pageCoordinates(c);g.buttons===1&&z(b)}};this.mouseWheel=
function(b,c){g.cancelEvent(c);b=g.wheelDelta(c);y(b)};this.touchStart=function(b,c){t=c.touches.length===1?true:false;u=c.touches.length===2?true:false;if(t){g.capture(null);g.capture(h);p=g.pageCoordinates(c.touches[0])}else if(u){b=g.pageCoordinates(c.touches[0]);var m=g.pageCoordinates(c.touches[1]);C=Math.sqrt((b.x-m.x)*(b.x-m.x)+(b.y-m.y)*(b.y-m.y))}else return;c.preventDefault()};this.touchEnd=function(b,c){var m=c.touches.length===0?true:false;t=c.touches.length===1?true:false;u=c.touches.length===
2?true:false;m&&D.mouseUp(null,null);if(t||u)D.touchStart(b,c)};this.touchMoved=function(b,c){if(t||u){c.preventDefault();if(t){if(p===null)return;b=g.pageCoordinates(c);z(b)}if(u){b=g.pageCoordinates(c.touches[0]);c=g.pageCoordinates(c.touches[1]);c=Math.sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));b=c/C;if(!(Math.abs(b-1)<0.05)){b=b>1?1:-1;C=c;y(b)}}}}};this.WalkMouseHandler=function(a,d,l){function o(i){var k=i.x-f.x;i=i.y-f.y;var s=j.create();j.identity(s);j.rotateY(s,k*z);k=q.create();k[0]=
0;k[1]=0;k[2]=-y*i;j.translate(s,k);j.multiply(s,x,x);w.paintGL();f=g.pageCoordinates(event)}var x=a,y=d,z=l,f=null;this.mouseDown=function(i,k){g.capture(null);g.capture(h);f=g.pageCoordinates(k)};this.mouseUp=function(){if(f!==null)f=null};this.mouseDrag=function(i,k){if(f!==null){i=g.pageCoordinates(k);o(i)}}};this.mouseDrag=function(a,d){if((this.initialized||!this.ctx)&&e&&e.mouseDrag)e.mouseDrag(a,d)};this.mouseMove=function(a,d){if((this.initialized||!this.ctx)&&e&&e.mouseMove)e.mouseMove(a,
d)};this.mouseDown=function(a,d){if((this.initialized||!this.ctx)&&e&&e.mouseDown)e.mouseDown(a,d)};this.mouseUp=function(a,d){if((this.initialized||!this.ctx)&&e&&e.mouseUp)e.mouseUp(a,d)};this.mouseWheel=function(a,d){if((this.initialized||!this.ctx)&&e&&e.mouseWheel)e.mouseWheel(a,d)};this.touchStart=function(a,d){if((this.initialized||!this.ctx)&&e&&e.touchStart)e.touchStart(a,d)};this.touchEnd=function(a,d){if((this.initialized||!this.ctx)&&e&&e.touchEnd)e.touchEnd(a,d)};this.touchMoved=function(a,
d){if((this.initialized||!this.ctx)&&e&&e.touchMoved)e.touchMoved(a,d)};this.handlePreload=function(){if(this.preloadingTextures===0&&this.preloadingBuffers===0){if(this.initialized){var a;for(a in this.updates)this.updates[a]();this.updates=[]}else this.initializeGL();this.resizeGL();this.paintGL()}};h.wtEncodeValue=F;var B=null,n=new Image;n.busy=false;n.onload=function(){h.src=n.src;if(B!=null)n.src=B;else n.busy=false;B=null};n.onerror=n.onload;this.loadImage=function(a){if(n.busy)B=a;else{n.src=
a;n.busy=true}}});
